﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;

namespace SNSpirit.Service.Access
{
    public class CookieWebAccessor : IWebAccessor
    {
        public CookieWebAccessor(CookieCollection cookies)
        {
            if (cookies == null)
                throw new ArgumentNullException("cookies");
            this._cookies = cookies;
        }

        public virtual WebRequest RequestProcess(WebRequest request)
        {
            HttpWebRequest httpReq = request as HttpWebRequest;
            if (httpReq != null)
            {
                if (httpReq.CookieContainer == null)
                    httpReq.CookieContainer = new CookieContainer();
                httpReq.CookieContainer.Add(this._cookies);
            }
            return request;
        }

        public virtual WebResponse ResponseProcess(WebResponse response)
        {
            return response;
        }

        #region private

        private CookieCollection _cookies;

        #endregion private
    }
}